************************************************************
* File Name: PartisanWorldviews_Replication_Recoding.do
* Created by: Rebecca Kreitzer
* Purpose:	Replication of Variable Recoding
************************************************************

/////////////////////////////
*general info*
/////////////////////////////


/////////////////////////////
* 1. Importing Raw Data 
/////////////////////////////

use PartisanWorldviews_Data_Original.dta, clear

/////////////////////////////
* 2. Descriptive Demographic Variables
/////////////////////////////

sum gender_female race_whiteonly race_black race_asian race_latino race_native race_other educ_7 age religattend_6 fiscal_conserv5 social_conserv5 partisan_dem partisan_indep partisan_rep party_demindrep

/////////////////////////////
* 1. Estimating the mean (standardized) score and standard deviation for each of the target groups 
/////////////////////////////

* 1a. Collapse the data to retrieve the mean for each group's social constructions (power and deservingness)
collapse (mean) pow_africanamericans_mean=pow_africanamericans		pow_native_mean=pow_native 				pow_asian_mean=pow_asian				pow_atheist_mean=pow_atheist ///
				pow_asylumseeker_mean=pow_asylumseeker				pow_attorneys_mean=pow_attorneys 		pow_bigbanks_mean=pow_bigbanks			pow_bigcorps_mean=pow_bigcorps ///
				pow_blm_mean=pow_blm								pow_bluecollar_mean=pow_bluecollar 		pow_tanf_mean=pow_tanf					pow_catholic_mean=pow_catholic ///
				pow_children_mean=pow_children						pow_collegeprof_mean=pow_collegeprof 	pow_congress_mean=pow_congress 			pow_criminals_mean=pow_criminals  ///
				pow_entrepreneur_mean=pow_entrepreneur				pow_dreamers_mean=pow_dreamers			pow_elderly_mean=pow_elderly			pow_environment_mean=pow_environment  ///
				pow_evangelical_mean=pow_evangelical				pow_exfelons_mean=pow_exfelons			pow_farmers_mean=pow_farmers			pow_feminists_mean=pow_feminists  ///
				pow_gunmanuf_mean=pow_gunmanuf 						pow_gunowners_mean=pow_gunowners 		pow_snap_mean=pow_snap 					pow_gaymen_mean=pow_gaymen  ///
				pow_gunvictims_mean=pow_gunvictims 					pow_homeless_mean=pow_homeless 			pow_homeowners_mean=pow_homeowners 		pow_illegalaliens_mean=pow_illegalaliens /// 
				pow_insuranceco_mean=pow_insuranceco 				pow_ice_mean=pow_ice 					pow_jews_mean=pow_jews 					pow_jobcreators_mean=pow_jobcreators  ///
				pow_laborunions_mean=pow_laborunions 				pow_latino_mean=pow_latino 				pow_lesbians_mean=pow_lesbians 			pow_marijsmoker_mean=pow_marijsmoker  ///
				pow_media_mean=pow_media 							pow_medicaid_mean=pow_medicaid 			pow_medicare_mean=pow_medicare 			pow_mentallyill_mean=pow_mentallyill  ///
				pow_metoo_mean=pow_metoo 							pow_middleclass_mean=pow_middleclass 	pow_migrantworker_mean=pow_migrantworker pow_military_mean=pow_military  ///
				pow_millennials_mean=pow_millennials 				pow_mothers_mean=pow_mothers 			pow_muslims_mean=pow_muslims 			pow_nra_mean=pow_nra  ///
				pow_opioiduser_mean=pow_opioiduser 					pow_aids_mean=pow_aids 					pow_police_mean=pow_police 				pow_polvictim_mean=pow_polvictim  ///
				pow_poorfamilies_mean=pow_poorfamilies 				pow_prisoners_mean=pow_prisoners 		pow_refugees_mean=pow_refugees 			pow_retirees_mean=pow_retirees  ///
				pow_sexualharassvictim_mean=pow_sexualharassvictim	pow_richpeople_mean=pow_richpeople 		pow_sexoffender_mean=pow_sexoffender  	pow_sexualharasser_mean=pow_sexualharasser /// 
				pow_singledad_mean=pow_singledad				 	pow_singlemom_mean=pow_singlemom 		pow_smallbusiness_mean=pow_smallbusiness pow_smokers_mean=pow_smokers  ///
				pow_soldiers_mean=pow_soldiers		 				pow_taxpayers_mean=pow_taxpayers 		pow_teachers_mean=pow_teachers 			pow_techworker_mean=pow_techworker  ///
				pow_transgender_mean=pow_transgender 				pow_unauthimm_mean=pow_unauthimm 		pow_unemployed_mean=pow_unemployed 		pow_uninsured_mean=pow_uninsured  ///
				pow_veterans_mean=pow_veterans 						pow_voters_mean=pow_voters 				pow_welfarecheats_mean=pow_welfarecheats pow_welfaremothers_mean=pow_welfaremothers  ///
				pow_whitecollar_mean=pow_whitecollar 				pow_whitemen_mean=pow_whitemen 			pow_whitenat_mean=pow_whitenat 			pow_whitewomen_mean=pow_whitewomen  ///
				pow_workingclass_mean=pow_workingclass 				pow_youngblackmen_mean=pow_youngblackmen 	pow_wrongfullyconvict_mean=pow_wrongfullyconvict ///
				des_africanamericans_mean=des_africanamericans		des_native_mean=des_native 				des_asian_mean=des_asian				des_atheist_mean=des_atheist ///
				des_asylumseeker_mean=des_asylumseeker				des_attorneys_mean=des_attorneys 		des_bigbanks_mean=des_bigbanks			des_bigcorps_mean=des_bigcorps ///
				des_blm_mean=des_blm								des_bluecollar_mean=des_bluecollar 		des_tanf_mean=des_tanf					des_catholic_mean=des_catholic ///
				des_children_mean=des_children						des_collegeprof_mean=des_collegeprof 	des_congress_mean=des_congress 			des_criminals_mean=des_criminals  ///
				des_entrepreneur_mean=des_entrepreneur				des_dreamers_mean=des_dreamers			des_elderly_mean=des_elderly			des_environment_mean=des_environment  ///
				des_evangelical_mean=des_evangelical				des_exfelons_mean=des_exfelons			des_farmers_mean=des_farmers			des_feminists_mean=des_feminists  ///
				des_gunmanuf_mean=des_gunmanuf 						des_gunowners_mean=des_gunowners 		des_snap_mean=des_snap 					des_gaymen_mean=des_gaymen  ///
				des_gunvictims_mean=des_gunvictims 					des_homeless_mean=des_homeless 			des_homeowners_mean=des_homeowners 		des_illegalaliens_mean=des_illegalaliens /// 
				des_insuranceco_mean=des_insuranceco 				des_ice_mean=des_ice 					des_jews_mean=des_jews 					des_jobcreators_mean=des_jobcreators  ///
				des_laborunions_mean=des_laborunions 				des_latino_mean=des_latino 				des_lesbians_mean=des_lesbians 			des_marijsmoker_mean=des_marijsmoker  ///
				des_media_mean=des_media 							des_medicaid_mean=des_medicaid 			des_medicare_mean=des_medicare 			des_mentallyill_mean=des_mentallyill  ///
				des_metoo_mean=des_metoo 							des_middleclass_mean=des_middleclass 	des_migrantworker_mean=des_migrantworker des_military_mean=des_military  ///
				des_millennials_mean=des_millennials 				des_mothers_mean=des_mothers 			des_muslims_mean=des_muslims 			des_nra_mean=des_nra  ///
				des_opioiduser_mean=des_opioiduser 					des_aids_mean=des_aids 					des_police_mean=des_police 				des_polvictim_mean=des_polvictim  ///
				des_poorfamilies_mean=des_poorfamilies 				des_prisoners_mean=des_prisoners 		des_refugees_mean=des_refugees 			des_retirees_mean=des_retirees  ///
				des_sexualharassvictim_mean=des_sexualharassvictim	des_richpeople_mean=des_richpeople 		des_sexoffender_mean=des_sexoffender  	des_sexualharasser_mean=des_sexualharasser /// 
				des_singledad_mean=des_singledad				 	des_singlemom_mean=des_singlemom 		des_smallbusiness_mean=des_smallbusiness des_smokers_mean=des_smokers  ///
				des_soldiers_mean=des_soldiers		 				des_taxpayers_mean=des_taxpayers 		des_teachers_mean=des_teachers 			des_techworker_mean=des_techworker  ///
				des_transgender_mean=des_transgender 				des_unauthimm_mean=des_unauthimm 		des_unemployed_mean=des_unemployed 		des_uninsured_mean=des_uninsured  ///
				des_veterans_mean=des_veterans 						des_voters_mean=des_voters 				des_welfarecheats_mean=des_welfarecheats des_welfaremothers_mean=des_welfaremothers  ///
				des_whitecollar_mean=des_whitecollar 				des_whitemen_mean=des_whitemen 			des_whitenat_mean=des_whitenat 			des_whitewomen_mean=des_whitewomen  ///
				des_workingclass_mean=des_workingclass 				des_youngblackmen_mean=des_youngblackmen 	des_wrongfullyconvict_mean=des_wrongfullyconvict
	
	rename *_mean *
	gen grouptemp = 1
 
reshape long pow_ des_, i(grouptemp) j(group) string
	drop grouptemp
	rename *_ *
	
	rename pow pow_all_mean
	rename des des_all_mean
	
	save "Exported Data Files/means_allgroups.dta", replace
	
* 1b. Collapse the data to retrieve the standard deviation for each group's social constructions (power and deservingness)	
use PartisanWorldviews_Data_Original.dta, clear

collapse(sd)	pow_africanamericans_sd=pow_africanamericans		pow_native_sd=pow_native 				pow_asian_sd=pow_asian					pow_atheist_sd=pow_atheist ///
				pow_asylumseeker_sd=pow_asylumseeker				pow_attorneys_sd=pow_attorneys 			pow_bigbanks_sd=pow_bigbanks			pow_bigcorps_sd=pow_bigcorps ///
				pow_blm_sd=pow_blm									pow_bluecollar_sd=pow_bluecollar 		pow_tanf_sd=pow_tanf					pow_catholic_sd=pow_catholic ///
				pow_children_sd=pow_children						pow_collegeprof_sd=pow_collegeprof 		pow_congress_sd=pow_congress 			pow_criminals_sd=pow_criminals  ///
				pow_entrepreneur_sd=pow_entrepreneur				pow_dreamers_sd=pow_dreamers			pow_elderly_sd=pow_elderly				pow_environment_sd=pow_environment  ///
				pow_evangelical_sd=pow_evangelical					pow_exfelons_sd=pow_exfelons			pow_farmers_sd=pow_farmers				pow_feminists_sd=pow_feminists  ///
				pow_gunmanuf_sd=pow_gunmanuf 						pow_gunowners_sd=pow_gunowners 			pow_snap_sd=pow_snap 					pow_gaymen_sd=pow_gaymen  ///
				pow_gunvictims_sd=pow_gunvictims 					pow_homeless_sd=pow_homeless 			pow_homeowners_sd=pow_homeowners 		pow_illegalaliens_sd=pow_illegalaliens /// 
				pow_insuranceco_sd=pow_insuranceco 					pow_ice_sd=pow_ice 						pow_jews_sd=pow_jews 					pow_jobcreators_sd=pow_jobcreators  ///
				pow_laborunions_sd=pow_laborunions 					pow_latino_sd=pow_latino 				pow_lesbians_sd=pow_lesbians 			pow_marijsmoker_sd=pow_marijsmoker  ///
				pow_media_sd=pow_media 								pow_medicaid_sd=pow_medicaid 			pow_medicare_sd=pow_medicare 			pow_mentallyill_sd=pow_mentallyill  ///
				pow_metoo_sd=pow_metoo 								pow_middleclass_sd=pow_middleclass 		pow_migrantworker_sd=pow_migrantworker 	pow_military_sd=pow_military  ///
				pow_millennials_sd=pow_millennials 					pow_mothers_sd=pow_mothers 				pow_muslims_sd=pow_muslims 				pow_nra_sd=pow_nra  ///
				pow_opioiduser_sd=pow_opioiduser 					pow_aids_sd=pow_aids 					pow_police_sd=pow_police 				pow_polvictim_sd=pow_polvictim  ///
				pow_poorfamilies_sd=pow_poorfamilies 				pow_prisoners_sd=pow_prisoners 			pow_refugees_sd=pow_refugees 			pow_retirees_sd=pow_retirees  ///
				pow_sexualharassvictim_sd=pow_sexualharassvictim	pow_richpeople_sd=pow_richpeople 		pow_sexoffender_sd=pow_sexoffender  	pow_sexualharasser_sd=pow_sexualharasser /// 
				pow_singledad_sd=pow_singledad				 		pow_singlemom_sd=pow_singlemom 			pow_smallbusiness_sd=pow_smallbusiness 	pow_smokers_sd=pow_smokers  ///
				pow_soldiers_sd=pow_soldiers		 				pow_taxpayers_sd=pow_taxpayers 			pow_teachers_sd=pow_teachers 			pow_techworker_sd=pow_techworker  ///
				pow_transgender_sd=pow_transgender 					pow_unauthimm_sd=pow_unauthimm 			pow_unemployed_sd=pow_unemployed 		pow_uninsured_sd=pow_uninsured  ///
				pow_veterans_sd=pow_veterans 						pow_voters_sd=pow_voters 				pow_welfarecheats_sd=pow_welfarecheats 	pow_welfaremothers_sd=pow_welfaremothers  ///
				pow_whitecollar_sd=pow_whitecollar 					pow_whitemen_sd=pow_whitemen 			pow_whitenat_sd=pow_whitenat 			pow_whitewomen_sd=pow_whitewomen  ///
				pow_workingclass_sd=pow_workingclass 				pow_youngblackmen_sd=pow_youngblackmen 	pow_wrongfullyconvict_sd=pow_wrongfullyconvict ///
				des_africanamericans_sd=des_africanamericans		des_native_sd=des_native 				des_asian_sd=des_asian					des_atheist_sd=des_atheist ///
				des_asylumseeker_sd=des_asylumseeker				des_attorneys_sd=des_attorneys 			des_bigbanks_sd=des_bigbanks			des_bigcorps_sd=des_bigcorps ///
				des_blm_sd=des_blm									des_bluecollar_sd=des_bluecollar 		des_tanf_sd=des_tanf					des_catholic_sd=des_catholic ///
				des_children_sd=des_children						des_collegeprof_sd=des_collegeprof 		des_congress_sd=des_congress 			des_criminals_sd=des_criminals  ///
				des_entrepreneur_sd=des_entrepreneur				des_dreamers_sd=des_dreamers			des_elderly_sd=des_elderly				des_environment_sd=des_environment  ///
				des_evangelical_sd=des_evangelical					des_exfelons_sd=des_exfelons			des_farmers_sd=des_farmers				des_feminists_sd=des_feminists  ///
				des_gunmanuf_sd=des_gunmanuf 						des_gunowners_sd=des_gunowners 			des_snap_sd=des_snap 					des_gaymen_sd=des_gaymen  ///
				des_gunvictims_sd=des_gunvictims 					des_homeless_sd=des_homeless 			des_homeowners_sd=des_homeowners 		des_illegalaliens_sd=des_illegalaliens /// 
				des_insuranceco_sd=des_insuranceco 					des_ice_sd=des_ice 						des_jews_sd=des_jews 					des_jobcreators_sd=des_jobcreators  ///
				des_laborunions_sd=des_laborunions 					des_latino_sd=des_latino 				des_lesbians_sd=des_lesbians 			des_marijsmoker_sd=des_marijsmoker  ///
				des_media_sd=des_media 								des_medicaid_sd=des_medicaid 			des_medicare_sd=des_medicare 			des_mentallyill_sd=des_mentallyill  ///
				des_metoo_sd=des_metoo 								des_middleclass_sd=des_middleclass 		des_migrantworker_sd=des_migrantworker 	des_military_sd=des_military  ///
				des_millennials_sd=des_millennials 					des_mothers_sd=des_mothers 				des_muslims_sd=des_muslims 				des_nra_sd=des_nra  ///
				des_opioiduser_sd=des_opioiduser 					des_aids_sd=des_aids 					des_police_sd=des_police 				des_polvictim_sd=des_polvictim  ///
				des_poorfamilies_sd=des_poorfamilies 				des_prisoners_sd=des_prisoners 			des_refugees_sd=des_refugees 			des_retirees_sd=des_retirees  ///
				des_sexualharassvictim_sd=des_sexualharassvictim	des_richpeople_sd=des_richpeople 		des_sexoffender_sd=des_sexoffender  	des_sexualharasser_sd=des_sexualharasser /// 
				des_singledad_sd=des_singledad				 		des_singlemom_sd=des_singlemom 			des_smallbusiness_sd=des_smallbusiness 	des_smokers_sd=des_smokers  ///
				des_soldiers_sd=des_soldiers		 				des_taxpayers_sd=des_taxpayers 			des_teachers_sd=des_teachers 			des_techworker_sd=des_techworker  ///
				des_transgender_sd=des_transgender 					des_unauthimm_sd=des_unauthimm 			des_unemployed_sd=des_unemployed 		des_uninsured_sd=des_uninsured  ///
				des_veterans_sd=des_veterans 						des_voters_sd=des_voters 				des_welfarecheats_sd=des_welfarecheats 	des_welfaremothers_sd=des_welfaremothers  ///
				des_whitecollar_sd=des_whitecollar 					des_whitemen_sd=des_whitemen 			des_whitenat_sd=des_whitenat 			des_whitewomen_sd=des_whitewomen  ///
				des_workingclass_sd=des_workingclass 				des_youngblackmen_sd=des_youngblackmen 	des_wrongfullyconvict_sd=des_wrongfullyconvict
	
	rename *_sd *
	gen grouptemp = 1
 
reshape long pow_ des_, i(grouptemp) j(group) string
	drop grouptemp
	rename *_ *
	
	rename pow pow_all_sd
	rename des des_all_sd
	
	save "Exported Data Files/sd_allgroups.dta", replace
	
* 1c. These data were then imported in to Tableau to create the scatterplot in Figure 1.

/////////////////////////////
* 2. Create average power and deserving scores for by Party ID
* 	- after collapsing the data by means by party, the file was exported to excel
/////////////////////////////

use PartisanWorldviews_Data_Original.dta, clear

* 2a. Collapse data to get the mean power and deserving for each group by partisanship
collapse (mean) pow_africanamericans_mean=pow_africanamericans		pow_native_mean=pow_native 				pow_asian_mean=pow_asian				pow_atheist_mean=pow_atheist ///
				pow_asylumseeker_mean=pow_asylumseeker				pow_attorneys_mean=pow_attorneys 		pow_bigbanks_mean=pow_bigbanks			pow_bigcorps_mean=pow_bigcorps ///
				pow_blm_mean=pow_blm								pow_bluecollar_mean=pow_bluecollar 		pow_tanf_mean=pow_tanf					pow_catholic_mean=pow_catholic ///
				pow_children_mean=pow_children						pow_collegeprof_mean=pow_collegeprof 	pow_congress_mean=pow_congress 			pow_criminals_mean=pow_criminals  ///
				pow_entrepreneur_mean=pow_entrepreneur				pow_dreamers_mean=pow_dreamers			pow_elderly_mean=pow_elderly			pow_environment_mean=pow_environment  ///
				pow_evangelical_mean=pow_evangelical				pow_exfelons_mean=pow_exfelons			pow_farmers_mean=pow_farmers			pow_feminists_mean=pow_feminists  ///
				pow_gunmanuf_mean=pow_gunmanuf 						pow_gunowners_mean=pow_gunowners 		pow_snap_mean=pow_snap 					pow_gaymen_mean=pow_gaymen  ///
				pow_gunvictims_mean=pow_gunvictims 					pow_homeless_mean=pow_homeless 			pow_homeowners_mean=pow_homeowners 		pow_illegalaliens_mean=pow_illegalaliens /// 
				pow_insuranceco_mean=pow_insuranceco 				pow_ice_mean=pow_ice 					pow_jews_mean=pow_jews 					pow_jobcreators_mean=pow_jobcreators  ///
				pow_laborunions_mean=pow_laborunions 				pow_latino_mean=pow_latino 				pow_lesbians_mean=pow_lesbians 			pow_marijsmoker_mean=pow_marijsmoker  ///
				pow_media_mean=pow_media 							pow_medicaid_mean=pow_medicaid 			pow_medicare_mean=pow_medicare 			pow_mentallyill_mean=pow_mentallyill  ///
				pow_metoo_mean=pow_metoo 							pow_middleclass_mean=pow_middleclass 	pow_migrantworker_mean=pow_migrantworker pow_military_mean=pow_military  ///
				pow_millennials_mean=pow_millennials 				pow_mothers_mean=pow_mothers 			pow_muslims_mean=pow_muslims 			pow_nra_mean=pow_nra  ///
				pow_opioiduser_mean=pow_opioiduser 					pow_aids_mean=pow_aids 					pow_police_mean=pow_police 				pow_polvictim_mean=pow_polvictim  ///
				pow_poorfamilies_mean=pow_poorfamilies 				pow_prisoners_mean=pow_prisoners 		pow_refugees_mean=pow_refugees 			pow_retirees_mean=pow_retirees  ///
				pow_sexualharassvictim_mean=pow_sexualharassvictim	pow_richpeople_mean=pow_richpeople 		pow_sexoffender_mean=pow_sexoffender  	pow_sexualharasser_mean=pow_sexualharasser /// 
				pow_singledad_mean=pow_singledad				 	pow_singlemom_mean=pow_singlemom 		pow_smallbusiness_mean=pow_smallbusiness pow_smokers_mean=pow_smokers  ///
				pow_soldiers_mean=pow_soldiers		 				pow_taxpayers_mean=pow_taxpayers 		pow_teachers_mean=pow_teachers 			pow_techworker_mean=pow_techworker  ///
				pow_transgender_mean=pow_transgender 				pow_unauthimm_mean=pow_unauthimm 		pow_unemployed_mean=pow_unemployed 		pow_uninsured_mean=pow_uninsured  ///
				pow_veterans_mean=pow_veterans 						pow_voters_mean=pow_voters 				pow_welfarecheats_mean=pow_welfarecheats pow_welfaremothers_mean=pow_welfaremothers  ///
				pow_whitecollar_mean=pow_whitecollar 				pow_whitemen_mean=pow_whitemen 			pow_whitenat_mean=pow_whitenat 			pow_whitewomen_mean=pow_whitewomen  ///
				pow_workingclass_mean=pow_workingclass 				pow_youngblackmen_mean=pow_youngblackmen 	pow_wrongfullyconvict_mean=pow_wrongfullyconvict ///
				des_africanamericans_mean=des_africanamericans		des_native_mean=des_native 				des_asian_mean=des_asian				des_atheist_mean=des_atheist ///
				des_asylumseeker_mean=des_asylumseeker				des_attorneys_mean=des_attorneys 		des_bigbanks_mean=des_bigbanks			des_bigcorps_mean=des_bigcorps ///
				des_blm_mean=des_blm								des_bluecollar_mean=des_bluecollar 		des_tanf_mean=des_tanf					des_catholic_mean=des_catholic ///
				des_children_mean=des_children						des_collegeprof_mean=des_collegeprof 	des_congress_mean=des_congress 			des_criminals_mean=des_criminals  ///
				des_entrepreneur_mean=des_entrepreneur				des_dreamers_mean=des_dreamers			des_elderly_mean=des_elderly			des_environment_mean=des_environment  ///
				des_evangelical_mean=des_evangelical				des_exfelons_mean=des_exfelons			des_farmers_mean=des_farmers			des_feminists_mean=des_feminists  ///
				des_gunmanuf_mean=des_gunmanuf 						des_gunowners_mean=des_gunowners 		des_snap_mean=des_snap 					des_gaymen_mean=des_gaymen  ///
				des_gunvictims_mean=des_gunvictims 					des_homeless_mean=des_homeless 			des_homeowners_mean=des_homeowners 		des_illegalaliens_mean=des_illegalaliens /// 
				des_insuranceco_mean=des_insuranceco 				des_ice_mean=des_ice 					des_jews_mean=des_jews 					des_jobcreators_mean=des_jobcreators  ///
				des_laborunions_mean=des_laborunions 				des_latino_mean=des_latino 				des_lesbians_mean=des_lesbians 			des_marijsmoker_mean=des_marijsmoker  ///
				des_media_mean=des_media 							des_medicaid_mean=des_medicaid 			des_medicare_mean=des_medicare 			des_mentallyill_mean=des_mentallyill  ///
				des_metoo_mean=des_metoo 							des_middleclass_mean=des_middleclass 	des_migrantworker_mean=des_migrantworker des_military_mean=des_military  ///
				des_millennials_mean=des_millennials 				des_mothers_mean=des_mothers 			des_muslims_mean=des_muslims 			des_nra_mean=des_nra  ///
				des_opioiduser_mean=des_opioiduser 					des_aids_mean=des_aids 					des_police_mean=des_police 				des_polvictim_mean=des_polvictim  ///
				des_poorfamilies_mean=des_poorfamilies 				des_prisoners_mean=des_prisoners 		des_refugees_mean=des_refugees 			des_retirees_mean=des_retirees  ///
				des_sexualharassvictim_mean=des_sexualharassvictim	des_richpeople_mean=des_richpeople 		des_sexoffender_mean=des_sexoffender  	des_sexualharasser_mean=des_sexualharasser /// 
				des_singledad_mean=des_singledad				 	des_singlemom_mean=des_singlemom 		des_smallbusiness_mean=des_smallbusiness des_smokers_mean=des_smokers  ///
				des_soldiers_mean=des_soldiers		 				des_taxpayers_mean=des_taxpayers 		des_teachers_mean=des_teachers 			des_techworker_mean=des_techworker  ///
				des_transgender_mean=des_transgender 				des_unauthimm_mean=des_unauthimm 		des_unemployed_mean=des_unemployed 		des_uninsured_mean=des_uninsured  ///
				des_veterans_mean=des_veterans 						des_voters_mean=des_voters 				des_welfarecheats_mean=des_welfarecheats des_welfaremothers_mean=des_welfaremothers  ///
				des_whitecollar_mean=des_whitecollar 				des_whitemen_mean=des_whitemen 			des_whitenat_mean=des_whitenat 			des_whitewomen_mean=des_whitewomen  ///
				des_workingclass_mean=des_workingclass 				des_youngblackmen_mean=des_youngblackmen 	des_wrongfullyconvict_mean=des_wrongfullyconvict , by(party_demindrep)

* 2b Reshape the data
	drop if party_demindrep == 1.5
	drop if party_demindrep == .
	rename *_mean *

reshape long pow_ des_, i(party_demindrep) j(group) string
	rename *_ *

* create partisan estimate variables
gen pow_dem = pow if party_demindrep == 1
gen pow_rep = pow if party_demindrep == 2
gen des_dem = des if party_demindrep == 1
gen des_rep = des if party_demindrep == 2

collapse pow_dem pow_rep des_dem des_rep, by(group)

rename pow_dem mean_pow_dem
rename des_dem mean_des_dem
rename pow_rep	mean_pow_rep
rename des_rep mean_des_rep

save "Exported Data Files/means_partyid.dta", replace

	
/////////////////////////////
*3. Create variable for analysis that represents how an individual scored specific groups controlling for individual level of "judginess"
/////////////////////////////

* 3a. Create average power and deserving scores for respondents

use PartisanWorldviews_Data_Original.dta, clear

egen avg_pow = rmean(pow_africanamericans 	pow_native  	pow_asian 		pow_atheist  		pow_asylumseeker			pow_attorneys 		pow_bigbanks 		pow_bigcorps  ///
				pow_blm					pow_bluecollar  	pow_tanf 		pow_catholic  		pow_children				pow_collegeprof  	pow_congress 		pow_criminals  ///
				pow_entrepreneur		pow_dreamers 		pow_elderly		pow_environment   	pow_evangelical				pow_exfelons 		pow_farmers			pow_feminists   ///
				pow_gunmanuf 			pow_gunowners 		pow_snap 		pow_gaymen   		pow_gunvictims 				pow_homeless 		pow_homeowners 		pow_illegalaliens  /// 
				pow_insuranceco 		pow_ice 			pow_jews  		pow_jobcreators  	pow_laborunions 			pow_latino 			pow_lesbians 		pow_marijsmoker  ///
				pow_media 				pow_medicaid 		pow_medicare 	pow_mentallyill   	pow_metoo 					pow_middleclass 	pow_migrantworker  	pow_military  ///
				pow_millennials  		pow_mothers 		pow_muslims 	pow_nra  			pow_opioiduser 				pow_aids 			pow_police 			pow_polvictim  ///
				pow_poorfamilies 		pow_prisoners 		pow_refugees 	pow_retirees  		pow_sexualharassvictim  	pow_richpeople  	pow_sexoffender  	pow_sexualharasser  ///
				pow_singledad 			pow_singlemom 		pow_smallbusiness  pow_smokers   	pow_soldiers 		 		pow_taxpayers 		pow_teachers 		pow_techworker  ///
				pow_transgender 		pow_unauthimm 		pow_unemployed 	pow_uninsured  		pow_veterans 				pow_voters  		pow_welfarecheats  	pow_welfaremothers  ///
				pow_whitecollar 		pow_whitemen 		pow_whitenat 	pow_whitewomen  	pow_workingclass 			pow_youngblackmen 	pow_wrongfullyconvict )
				
	
egen avg_des = rmean(des_africanamericans 	des_native  		des_asian 		des_atheist  		des_asylumseeker		des_attorneys 		des_bigbanks 		des_bigcorps  ///
				des_blm					des_bluecollar  	des_tanf 			des_catholic  		des_children			des_collegeprof  	des_congress 		des_criminals  ///
				des_entrepreneur		des_dreamers 		des_elderly			des_environment  	des_evangelical			des_exfelons 		des_farmers			des_feminists   ///
				des_gunmanuf 			des_gunowners 		des_snap 			des_gaymen   		des_gunvictims 			des_homeless 		des_homeowners 		des_illegalaliens  /// 
				des_insuranceco 		des_ice 			des_jews  			des_jobcreators	  	des_laborunions 		des_latino 			des_lesbians 		des_marijsmoker  ///
				des_media 				des_medicaid 		des_medicare 		des_mentallyill   	des_metoo 				des_middleclass 	des_migrantworker  	des_military  ///
				des_millennials  		des_mothers 		des_muslims 		des_nra  			des_opioiduser 			des_aids 			des_police 			des_polvictim  ///
				des_poorfamilies 		des_prisoners 		des_refugees 		des_retirees  		des_sexualharassvictim  des_richpeople  	des_sexoffender  	des_sexualharasser  ///
				des_singledad 			des_singlemom 		des_smallbusiness 	des_smokers   		des_soldiers 		 	des_taxpayers 		des_teachers 		des_techworker  ///
				des_transgender 		des_unauthimm 		des_unemployed 		des_uninsured  		des_veterans 			des_voters  		des_welfarecheats  	des_welfaremothers  ///
				des_whitecollar 		des_whitemen 		des_whitenat 		des_whitewomen  	des_workingclass 		des_youngblackmen 	des_wrongfullyconvict )
	
* 3b. Create variable for the difference between how a respondent rated groups on average relative to each group

gen pow_africanamericans_dif = pow_africanamericans - avg_pow
gen pow_native_dif = pow_native - avg_pow
gen pow_asian_dif = pow_asian - avg_pow
gen pow_atheist_dif = pow_atheist  - avg_pow
gen pow_asylumseeker_dif = pow_asylumseeker - avg_pow
gen pow_attorneys_dif = pow_attorneys - avg_pow
gen pow_bigbanks_dif = pow_bigbanks - avg_pow
gen pow_bigcorps_dif = pow_bigcorps - avg_pow

gen pow_blm_dif = pow_blm - avg_pow
gen pow_bluecollar_dif = pow_bluecollar - avg_pow
gen pow_tanf_dif = pow_tanf - avg_pow
gen pow_catholic_dif = pow_catholic - avg_pow
gen pow_children_dif = pow_children - avg_pow
gen pow_collegeprof_dif = pow_collegeprof - avg_pow
gen pow_congress_dif = pow_congress - avg_pow
gen pow_criminals_dif = pow_criminals - avg_pow

gen pow_entrepreneur_dif = pow_entrepreneur - avg_pow
gen pow_dreamers_dif = pow_dreamers - avg_pow
gen pow_elderly_dif = pow_elderly - avg_pow
gen pow_environment_dif = pow_environment - avg_pow
gen pow_evangelical_dif = pow_evangelical - avg_pow
gen pow_exfelons_dif = pow_exfelons - avg_pow
gen pow_farmers_dif = pow_farmers - avg_pow
gen pow_feminists_dif = pow_feminists - avg_pow

gen pow_gunmanuf_dif = pow_gunmanuf - avg_pow
gen pow_gunowners_dif = pow_gunowners - avg_pow
gen pow_snap_dif = pow_snap - avg_pow
gen pow_gaymen_dif = pow_gaymen - avg_pow
gen pow_gunvictims_dif = pow_gunvictims - avg_pow
gen pow_homeless_dif = pow_homeless - avg_pow
gen pow_homeowners_dif = pow_homeowners - avg_pow
gen pow_illegalaliens_dif = pow_illegalaliens - avg_pow

gen pow_insuranceco_dif = pow_insuranceco  - avg_pow
gen pow_ice_dif = pow_ice  - avg_pow
gen pow_jews_dif = pow_jews - avg_pow
gen pow_jobcreators_dif = pow_jobcreators - avg_pow
gen pow_laborunions_dif = pow_laborunions - avg_pow
gen pow_latino_dif = pow_latino - avg_pow
gen pow_lesbians_dif = pow_lesbians - avg_pow
gen pow_marijsmoker_dif = pow_marijsmoker - avg_pow

gen pow_media_dif = pow_media - avg_pow
gen pow_medicaid_dif = pow_medicaid  - avg_pow
gen pow_medicare_dif = pow_medicare - avg_pow
gen pow_mentallyill_dif = pow_mentallyill - avg_pow
gen pow_metoo_dif = pow_metoo  - avg_pow
gen pow_middleclass_dif = pow_middleclass - avg_pow
gen pow_migrantworker_dif = pow_migrantworker - avg_pow
gen pow_military_dif = pow_military	 - avg_pow			
				
gen pow_millennials_dif = pow_millennials - avg_pow
gen pow_mothers_dif = pow_mothers - avg_pow
gen pow_muslims_dif = pow_muslims - avg_pow
gen pow_nra_dif = pow_nra   - avg_pow
gen pow_opioiduser_dif = pow_opioiduser - avg_pow
gen pow_aids_dif = pow_aids - avg_pow
gen pow_police_dif = pow_police  - avg_pow
gen pow_polvictim_dif = pow_polvictim - avg_pow		
				
gen pow_poorfamilies_dif = pow_poorfamilies - avg_pow
gen pow_prisoners_dif = pow_prisoners - avg_pow
gen pow_refugees_dif = pow_refugees - avg_pow
gen pow_retirees_dif = pow_retirees - avg_pow
gen pow_sexualharassvictim_dif = pow_sexualharassvictim - avg_pow
gen pow_richpeople_dif = pow_richpeople - avg_pow
gen pow_sexoffender_dif = pow_sexoffender  - avg_pow
gen pow_sexualharasser_dif = pow_sexualharasser	 - avg_pow		
				
gen pow_singledad_dif = pow_singledad - avg_pow
gen pow_singlemom_dif = pow_singlemom - avg_pow
gen pow_smallbusiness_dif = pow_smallbusiness  - avg_pow
gen pow_smokers_dif = pow_smokers - avg_pow
gen pow_soldiers_dif = pow_soldiers  - avg_pow
gen pow_taxpayers_dif = pow_taxpayers - avg_pow
gen pow_teachers_dif = pow_teachers - avg_pow
gen pow_techworker_dif = pow_techworker  - avg_pow				
				
gen pow_transgender_dif = pow_transgender  - avg_pow
gen pow_unauthimm_dif = pow_unauthimm - avg_pow
gen pow_unemployed_dif = pow_unemployed - avg_pow
gen pow_uninsured_dif = pow_uninsured - avg_pow
gen pow_veterans_dif = pow_veterans - avg_pow
gen pow_voters_dif = pow_voters - avg_pow
gen pow_welfarecheats_dif = pow_welfarecheats - avg_pow
gen pow_welfaremothers_dif = pow_welfaremothers - avg_pow			
											
gen pow_whitecollar_dif = pow_whitecollar - avg_pow
gen pow_whitemen_dif = pow_whitemen - avg_pow
gen pow_whitenat_dif = pow_whitenat - avg_pow
gen pow_whitewomen_dif = pow_whitewomen - avg_pow
gen pow_workingclass_dif = pow_workingclass - avg_pow
gen pow_youngblackmen_dif = pow_youngblackmen - avg_pow
gen pow_wrongfullyconvict_dif = pow_wrongfullyconvict - avg_pow
			
				

gen des_africanamericans_dif = des_africanamericans - avg_des
gen des_native_dif = des_native - avg_des
gen des_asian_dif = des_asian - avg_des
gen des_atheist_dif = des_atheist  - avg_des
gen des_asylumseeker_dif = des_asylumseeker - avg_des
gen des_attorneys_dif = des_attorneys - avg_des
gen des_bigbanks_dif = des_bigbanks - avg_des
gen des_bigcorps_dif = des_bigcorps - avg_des

gen des_blm_dif = des_blm - avg_des
gen des_bluecollar_dif = des_bluecollar - avg_des
gen des_tanf_dif = des_tanf - avg_des
gen des_catholic_dif = des_catholic - avg_des
gen des_children_dif = des_children - avg_des
gen des_collegeprof_dif = des_collegeprof - avg_des
gen des_congress_dif = des_congress - avg_des
gen des_criminals_dif = des_criminals - avg_des

gen des_entrepreneur_dif = des_entrepreneur - avg_des
gen des_dreamers_dif = des_dreamers - avg_des
gen des_elderly_dif = des_elderly - avg_des
gen des_environment_dif = des_environment - avg_des
gen des_evangelical_dif = des_evangelical - avg_des
gen des_exfelons_dif = des_exfelons - avg_des
gen des_farmers_dif = des_farmers - avg_des
gen des_feminists_dif = des_feminists - avg_des

gen des_gunmanuf_dif = des_gunmanuf - avg_des
gen des_gunowners_dif = des_gunowners - avg_des
gen des_snap_dif = des_snap - avg_des
gen des_gaymen_dif = des_gaymen - avg_des
gen des_gunvictims_dif = des_gunvictims - avg_des
gen des_homeless_dif = des_homeless - avg_des
gen des_homeowners_dif = des_homeowners - avg_des
gen des_illegalaliens_dif = des_illegalaliens - avg_des

gen des_insuranceco_dif = des_insuranceco  - avg_des
gen des_ice_dif = des_ice  - avg_des
gen des_jews_dif = des_jews - avg_des
gen des_jobcreators_dif = des_jobcreators - avg_des
gen des_laborunions_dif = des_laborunions - avg_des
gen des_latino_dif = des_latino - avg_des
gen des_lesbians_dif = des_lesbians - avg_des
gen des_marijsmoker_dif = des_marijsmoker - avg_des

gen des_media_dif = des_media - avg_des
gen des_medicaid_dif = des_medicaid  - avg_des
gen des_medicare_dif = des_medicare - avg_des
gen des_mentallyill_dif = des_mentallyill - avg_des
gen des_metoo_dif = des_metoo  - avg_des
gen des_middleclass_dif = des_middleclass - avg_des
gen des_migrantworker_dif = des_migrantworker - avg_des
gen des_military_dif = des_military	 - avg_des			
				
gen des_millennials_dif = des_millennials - avg_des
gen des_mothers_dif = des_mothers - avg_des
gen des_muslims_dif = des_muslims - avg_des
gen des_nra_dif = des_nra   - avg_des
gen des_opioiduser_dif = des_opioiduser - avg_des
gen des_aids_dif = des_aids - avg_des
gen des_police_dif = des_police  - avg_des
gen des_polvictim_dif = des_polvictim - avg_des				
				
gen des_poorfamilies_dif = des_poorfamilies - avg_des
gen des_prisoners_dif = des_prisoners - avg_des
gen des_refugees_dif = des_refugees - avg_des
gen des_retirees_dif = des_retirees - avg_des
gen des_sexualharassvictim_dif = des_sexualharassvictim - avg_des
gen des_richpeople_dif = des_richpeople - avg_des
gen des_sexoffender_dif = des_sexoffender  - avg_des
gen des_sexualharasser_dif = des_sexualharasser	 - avg_des		
				
gen des_singledad_dif = des_singledad - avg_des
gen des_singlemom_dif = des_singlemom - avg_des
gen des_smallbusiness_dif = des_smallbusiness  - avg_des
gen des_smokers_dif = des_smokers - avg_des
gen des_soldiers_dif = des_soldiers  - avg_des
gen des_taxpayers_dif = des_taxpayers - avg_des
gen des_teachers_dif = des_teachers - avg_des
gen des_techworker_dif = des_techworker  - avg_des				
				
gen des_transgender_dif = des_transgender  - avg_des
gen des_unauthimm_dif = des_unauthimm - avg_des
gen des_unemployed_dif = des_unemployed - avg_des
gen des_uninsured_dif = des_uninsured - avg_des
gen des_veterans_dif = des_veterans - avg_des
gen des_voters_dif = des_voters - avg_des
gen des_welfarecheats_dif = des_welfarecheats - avg_des
gen des_welfaremothers_dif = des_welfaremothers	 - avg_des		
											
gen des_whitecollar_dif = des_whitecollar - avg_des
gen des_whitemen_dif = des_whitemen - avg_des
gen des_whitenat_dif = des_whitenat - avg_des
gen des_whitewomen_dif = des_whitewomen - avg_des
gen des_workingclass_dif = des_workingclass - avg_des
gen des_youngblackmen_dif = des_youngblackmen - avg_des
gen des_wrongfullyconvict_dif = des_wrongfullyconvict - avg_des	

/////////////////////////////
*4. Recode some variables so that the scatterplots resemble Schneider and Ingram 1993 orientation
/////////////////////////////

gen des_workingclass_si = des_workingclass*-1	
gen des_teachers_si = des_teachers*-1	
gen des_middleclass_si = des_middleclass*-1	
gen des_mothers_si = des_mothers*-1	
gen des_singledad_si = des_singledad*-1	
gen des_veterans_si = des_veterans*-1	
gen des_elderly_si = des_elderly*-1	
gen des_farmers_si = des_farmers*-1	
gen des_smallbusiness_si = des_smallbusiness*-1	
gen des_bluecollar_si = des_bluecollar*-1	
gen des_illegalaliens_si = des_illegalaliens*-1	
gen des_unauthimm_si = des_unauthimm*-1
gen des_blm_si = des_blm*-1	
gen des_ice_si = des_ice*-1	
gen des_opioiduser_si = des_opioiduser*-1	
gen des_nra_si = des_nra*-1	
gen des_richpeople_si = des_richpeople*-1	
gen des_asylumseeker_si = des_asylumseeker*-1	
gen des_evangelical_si = des_evangelical*-1	
gen des_transgender_si = des_transgender*-1
gen des_dreamers_si = des_dreamers*-1	
gen des_latino_si = des_latino*-1	
gen des_migrantworker_si = des_migrantworker*-1	
gen des_police_si = des_police*-1	
gen des_refugees_si = des_refugees*-1	
gen des_whitenat_si = des_whitenat*-1	
gen des_gunmanuf_si = des_gunmanuf*-1	
gen des_bigcorps_si = des_bigcorps*-1	
gen des_bigbanks_si = des_bigbanks*-1	
gen des_military_si = des_military*-1
gen des_congress_si = des_congress*-1
gen des_insuranceco_si = des_insuranceco*-1

save PartisanWorldviews_Data_Final, replace

/////////////////////////////
*5. Identify which groups have low and high consensus
/////////////////////////////

* 5a. Calculate the Grand Standard Deviations (GSD) for each group
	
collapse (sd)	pow_africanamericans_dif_sd=pow_africanamericans_dif		pow_native_dif_sd=pow_native_dif 				///
				pow_asian_dif_sd=pow_asian_dif								pow_atheist_dif_sd=pow_atheist_dif ///
				pow_asylumseeker_dif_sd=pow_asylumseeker_dif				pow_attorneys_dif_sd=pow_attorneys_dif 			///
				pow_bigbanks_dif_sd=pow_bigbanks_dif						pow_bigcorps_dif_sd=pow_bigcorps_dif ///
				pow_blm_dif_sd=pow_blm_dif									pow_bluecollar_dif_sd=pow_bluecollar_dif 		///
				pow_tanf_dif_sd=pow_tanf_dif								pow_catholic_dif_sd=pow_catholic_dif ///
				pow_children_dif_sd=pow_children_dif						pow_collegeprof_dif_sd=pow_collegeprof_dif 		///
				pow_congress_dif_sd=pow_congress_dif 						pow_criminals_dif_sd=pow_criminals_dif  ///
				pow_entrepreneur_dif_sd=pow_entrepreneur_dif				pow_dreamers_dif_sd=pow_dreamers_dif			///
				pow_elderly_dif_sd=pow_elderly_dif							pow_environment_dif_sd=pow_environment_dif  ///
				pow_evangelical_dif_sd=pow_evangelical_dif					pow_exfelons_dif_sd=pow_exfelons_dif			///
				pow_farmers_dif_sd=pow_farmers_dif							pow_feminists_dif_sd=pow_feminists_dif  ///
				pow_gunmanuf_dif_sd=pow_gunmanuf_dif 						pow_gunowners_dif_sd=pow_gunowners_dif 			///
				pow_snap_dif_sd=pow_snap_dif 								pow_gaymen_dif_sd=pow_gaymen_dif  ///
				pow_gunvictims_dif_sd=pow_gunvictims_dif 					pow_homeless_dif_sd=pow_homeless_dif 			///
				pow_homeowners_dif_sd=pow_homeowners_dif 					pow_illegalaliens_dif_sd=pow_illegalaliens_dif /// 
				pow_insuranceco_dif_sd=pow_insuranceco_dif 					pow_ice_dif_sd=pow_ice_dif 						///
				pow_jews_dif_sd=pow_jews_dif 								pow_jobcreators_dif_sd=pow_jobcreators_dif  ///
				pow_laborunions_dif_sd=pow_laborunions_dif 					pow_latino_dif_sd=pow_latino_dif 				///
				pow_lesbians_dif_sd=pow_lesbians_dif 						pow_marijsmoker_dif_sd=pow_marijsmoker_dif  ///
				pow_media_dif_sd=pow_media_dif 								pow_medicaid_dif_sd=pow_medicaid_dif 			///
				pow_medicare_dif_sd=pow_medicare_dif 						pow_mentallyill_dif_sd=pow_mentallyill_dif  ///
				pow_metoo_dif_sd=pow_metoo_dif 								pow_middleclass_dif_sd=pow_middleclass_dif 		///
				pow_migrantworker_dif_sd=pow_migrantworker_dif 				pow_military_dif_sd=pow_military_dif  ///
				pow_millennials_dif_sd=pow_millennials_dif 					pow_mothers_dif_sd=pow_mothers_dif 				///
				pow_muslims_dif_sd=pow_muslims_dif 							pow_nra_dif_sd=pow_nra_dif  ///
				pow_opioiduser_dif_sd=pow_opioiduser_dif 					pow_aids_dif_sd=pow_aids_dif 					///
				pow_police_dif_sd=pow_police_dif 							pow_polvictim_dif_sd=pow_polvictim_dif  ///
				pow_poorfamilies_dif_sd=pow_poorfamilies_dif 				pow_prisoners_dif_sd=pow_prisoners_dif 			///
				pow_refugees_dif_sd=pow_refugees_dif 						pow_retirees_dif_sd=pow_retirees_dif  ///
				pow_sexualharassvictim_dif_sd=pow_sexualharassvictim_dif	pow_richpeople_dif_sd=pow_richpeople_dif 		///
				pow_sexoffender_dif_sd=pow_sexoffender_dif  				pow_sexualharasser_dif_sd=pow_sexualharasser_dif /// 
				pow_singledad_dif_sd=pow_singledad_dif				 		pow_singlemom_dif_sd=pow_singlemom_dif 			///
				pow_smallbusiness_dif_sd=pow_smallbusiness_dif 				pow_smokers_dif_sd=pow_smokers_dif  ///
				pow_soldiers_dif_sd=pow_soldiers_dif		 				pow_taxpayers_dif_sd=pow_taxpayers_dif 			///
				pow_teachers_dif_sd=pow_teachers_dif 						pow_techworker_dif_sd=pow_techworker_dif  ///
				pow_transgender_dif_sd=pow_transgender_dif 					pow_unauthimm_dif_sd=pow_unauthimm_dif 			///
				pow_unemployed_dif_sd=pow_unemployed_dif 					pow_uninsured_dif_sd=pow_uninsured_dif  ///
				pow_veterans_dif_sd=pow_veterans_dif 						pow_voters_dif_sd=pow_voters_dif 				///
				pow_welfarecheats_dif_sd=pow_welfarecheats_dif 				pow_welfaremothers_dif_sd=pow_welfaremothers_dif  ///
				pow_whitecollar_dif_sd=pow_whitecollar_dif 					pow_whitemen_dif_sd=pow_whitemen_dif 			///
				pow_whitenat_dif_sd=pow_whitenat_dif 						pow_whitewomen_dif_sd=pow_whitewomen_dif  ///
				pow_workingclass_dif_sd=pow_workingclass_dif 				pow_youngblackmen_dif_sd=pow_youngblackmen_dif 	///
				pow_wrongfullyconvict_dif_sd=pow_wrongfullyconvict_dif ///
				des_africanamericans_dif_sd=des_africanamericans_dif		des_native_dif_sd=des_native_dif 				///
				des_asian_dif_sd=des_asian_dif								des_atheist_dif_sd=des_atheist_dif ///
				des_asylumseeker_dif_sd=des_asylumseeker_dif				des_attorneys_dif_sd=des_attorneys_dif 			///
				des_bigbanks_dif_sd=des_bigbanks_dif						des_bigcorps_dif_sd=des_bigcorps_dif ///
				des_blm_dif_sd=des_blm_dif									des_bluecollar_dif_sd=des_bluecollar_dif 		///
				des_tanf_dif_sd=des_tanf_dif								des_catholic_dif_sd=des_catholic_dif ///
				des_children_dif_sd=des_children_dif						des_collegeprof_dif_sd=des_collegeprof_dif 		///
				des_congress_dif_sd=des_congress_dif 						des_criminals_dif_sd=des_criminals_dif  ///
				des_entrepreneur_dif_sd=des_entrepreneur_dif				des_dreamers_dif_sd=des_dreamers_dif			///
				des_elderly_dif_sd=des_elderly_dif							des_environment_dif_sd=des_environment_dif  ///
				des_evangelical_dif_sd=des_evangelical_dif					des_exfelons_dif_sd=des_exfelons_dif			///
				des_farmers_dif_sd=des_farmers_dif							des_feminists_dif_sd=des_feminists_dif  ///
				des_gunmanuf_dif_sd=des_gunmanuf_dif 						des_gunowners_dif_sd=des_gunowners_dif 			///
				des_snap_dif_sd=des_snap_dif 								des_gaymen_dif_sd=des_gaymen_dif  ///
				des_gunvictims_dif_sd=des_gunvictims_dif 					des_homeless_dif_sd=des_homeless_dif 			///
				des_homeowners_dif_sd=des_homeowners_dif 					des_illegalaliens_dif_sd=des_illegalaliens_dif /// 
				des_insuranceco_dif_sd=des_insuranceco_dif 					des_ice_dif_sd=des_ice_dif 						///
				des_jews_dif_sd=des_jews_dif 								des_jobcreators_dif_sd=des_jobcreators_dif  ///
				des_laborunions_dif_sd=des_laborunions_dif 					des_latino_dif_sd=des_latino_dif 				///
				des_lesbians_dif_sd=des_lesbians_dif 						des_marijsmoker_dif_sd=des_marijsmoker_dif  ///
				des_media_dif_sd=des_media_dif 								des_medicaid_dif_sd=des_medicaid_dif 			///
				des_medicare_dif_sd=des_medicare_dif 						des_mentallyill_dif_sd=des_mentallyill_dif  ///
				des_metoo_dif_sd=des_metoo_dif 								des_middleclass_dif_sd=des_middleclass_dif 		///
				des_migrantworker_dif_sd=des_migrantworker_dif 				des_military_dif_sd=des_military_dif  ///
				des_millennials_dif_sd=des_millennials_dif 					des_mothers_dif_sd=des_mothers_dif 				///
				des_muslims_dif_sd=des_muslims_dif 							des_nra_dif_sd=des_nra_dif  ///
				des_opioiduser_dif_sd=des_opioiduser_dif 					des_aids_dif_sd=des_aids_dif 					///
				des_police_dif_sd=des_police_dif 							des_polvictim_dif_sd=des_polvictim_dif  ///
				des_poorfamilies_dif_sd=des_poorfamilies_dif 				des_prisoners_dif_sd=des_prisoners_dif 			///
				des_refugees_dif_sd=des_refugees_dif 						des_retirees_dif_sd=des_retirees_dif  ///
				des_sexualharassvictim_dif_sd=des_sexualharassvictim_dif	des_richpeople_dif_sd=des_richpeople_dif 		///
				des_sexoffender_dif_sd=des_sexoffender_dif  				des_sexualharasser_dif_sd=des_sexualharasser_dif /// 
				des_singledad_dif_sd=des_singledad_dif				 		des_singlemom_dif_sd=des_singlemom_dif 			///
				des_smallbusiness_dif_sd=des_smallbusiness_dif 				des_smokers_dif_sd=des_smokers_dif  ///
				des_soldiers_dif_sd=des_soldiers_dif		 				des_taxpayers_dif_sd=des_taxpayers_dif 			///
				des_teachers_dif_sd=des_teachers_dif 						des_techworker_dif_sd=des_techworker_dif  ///
				des_transgender_dif_sd=des_transgender_dif 					des_unauthimm_dif_sd=des_unauthimm_dif 			///
				des_unemployed_dif_sd=des_unemployed_dif 					des_uninsured_dif_sd=des_uninsured_dif  ///
				des_veterans_dif_sd=des_veterans_dif 						des_voters_dif_sd=des_voters_dif 				///
				des_welfarecheats_dif_sd=des_welfarecheats_dif 				des_welfaremothers_dif_sd=des_welfaremothers_dif  ///
				des_whitecollar_dif_sd=des_whitecollar_dif 					des_whitemen_dif_sd=des_whitemen_dif 			///
				des_whitenat_dif_sd=des_whitenat_dif 						des_whitewomen_dif_sd=des_whitewomen_dif  ///
				des_workingclass_dif_sd=des_workingclass_dif 				des_youngblackmen_dif_sd=des_youngblackmen_dif 	///
				des_wrongfullyconvict_dif_sd=des_wrongfullyconvict_dif
	
	
	gen grouptemp = 1
  	rename *_dif_sd *
	
reshape long pow_ des_, i(grouptemp) j(group) string
	drop grouptemp
	rename *_ *
	
	rename pow pow_all_gsd
	rename des des_all_gsd
	
	save "Exported Data Files/gsd_allgroups.dta", replace


	expand 2, gen(group_deserving)
	gen group_power = 1 if group_deserving == 0
		replace group_power = 0 if group_power == .
	
	gen all_dif_sd = pow_all_gsd if group_power == 1
	replace all_dif_sd = des_all_gsd if group_deserving == 1
	
		 
*5b. In order to calculate the SD of the SDs (GSD) first, get the SD of the SD for all respondents
	

gen des_all_dif_sd = all_dif_sd if group_deserving == 1
gen pow_all_dif_sd = all_dif_sd if group_deserving == 0

sum des_all_dif_sd

/*
    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
des_all_di~d |         87    22.60654    3.532012   17.30569   31.21692
*/

di 3.532012/2
* 1.766006

* 5c. Identify groups with overall high and low consensus among all respondents 
	
gen des_all_sd_sdcat2 = 0 if group_deserving == 1
replace des_all_sd_sdcat2 = .5 if des_all_dif_sd > (22.60654 + 1.766006) & group_deserving==1
replace des_all_sd_sdcat2 = -.5 if des_all_dif_sd < (22.60654 - 1.766006) & group_deserving==1

replace des_all_sd_sdcat2 = 1 if des_all_dif_sd > (22.60654 + 3.532012) & group_deserving==1
replace des_all_sd_sdcat2 = -1 if des_all_dif_sd < (22.60654 - 3.532012) & group_deserving==1

replace des_all_sd_sdcat2 = 1.5 if des_all_dif_sd > (22.60654 + 3.532012 + 1.766006) & group_deserving==1
replace des_all_sd_sdcat2 = -1.5 if des_all_dif_sd < (22.60654 - 3.532012 - 1.766006) & group_deserving==1

replace des_all_sd_sdcat2 = 2 if des_all_dif_sd > (22.60654 + 3.532012 + 3.532012) & group_deserving==1
replace des_all_sd_sdcat2 = -2 if des_all_dif_sd < (22.60654 - 3.532012 - 3.532012) & group_deserving==1

gen consensus_all_des_low = 0 if group_deserving == 1
replace consensus_all_des_low = 1 if des_all_sd_sdcat2 > .5 

gen consensus_all_des_high = 0 if group_deserving == 1
replace consensus_all_des_high = 1 if des_all_sd_sdcat < -.5

drop pow_all_gsd des_all_gsd group_deserving group_power all_dif_sd

collapse (mean) des_all_dif_sd pow_all_dif_sd des_all_sd_sdcat2 consensus_all_des_low consensus_all_des_high, by(group)

* save and export
save "Exported Data Files/sd_allgroups_sdcat.dta", replace


*5d. Calculate the Grand Standard Deviations (GSD) for each group, by Party ID
use PartisanWorldviews_Data_Final, clear

collapse (sd)	pow_africanamericans_dif_sd=pow_africanamericans_dif		pow_native_dif_sd=pow_native_dif 				///
				pow_asian_dif_sd=pow_asian_dif								pow_atheist_dif_sd=pow_atheist_dif ///
				pow_asylumseeker_dif_sd=pow_asylumseeker_dif				pow_attorneys_dif_sd=pow_attorneys_dif 			///
				pow_bigbanks_dif_sd=pow_bigbanks_dif						pow_bigcorps_dif_sd=pow_bigcorps_dif ///
				pow_blm_dif_sd=pow_blm_dif									pow_bluecollar_dif_sd=pow_bluecollar_dif 		///
				pow_tanf_dif_sd=pow_tanf_dif								pow_catholic_dif_sd=pow_catholic_dif ///
				pow_children_dif_sd=pow_children_dif						pow_collegeprof_dif_sd=pow_collegeprof_dif 		///
				pow_congress_dif_sd=pow_congress_dif 						pow_criminals_dif_sd=pow_criminals_dif  ///
				pow_entrepreneur_dif_sd=pow_entrepreneur_dif				pow_dreamers_dif_sd=pow_dreamers_dif			///
				pow_elderly_dif_sd=pow_elderly_dif							pow_environment_dif_sd=pow_environment_dif  ///
				pow_evangelical_dif_sd=pow_evangelical_dif					pow_exfelons_dif_sd=pow_exfelons_dif			///
				pow_farmers_dif_sd=pow_farmers_dif							pow_feminists_dif_sd=pow_feminists_dif  ///
				pow_gunmanuf_dif_sd=pow_gunmanuf_dif 						pow_gunowners_dif_sd=pow_gunowners_dif 			///
				pow_snap_dif_sd=pow_snap_dif 								pow_gaymen_dif_sd=pow_gaymen_dif  ///
				pow_gunvictims_dif_sd=pow_gunvictims_dif 					pow_homeless_dif_sd=pow_homeless_dif 			///
				pow_homeowners_dif_sd=pow_homeowners_dif 					pow_illegalaliens_dif_sd=pow_illegalaliens_dif /// 
				pow_insuranceco_dif_sd=pow_insuranceco_dif 					pow_ice_dif_sd=pow_ice_dif 						///
				pow_jews_dif_sd=pow_jews_dif 								pow_jobcreators_dif_sd=pow_jobcreators_dif  ///
				pow_laborunions_dif_sd=pow_laborunions_dif 					pow_latino_dif_sd=pow_latino_dif 				///
				pow_lesbians_dif_sd=pow_lesbians_dif 						pow_marijsmoker_dif_sd=pow_marijsmoker_dif  ///
				pow_media_dif_sd=pow_media_dif 								pow_medicaid_dif_sd=pow_medicaid_dif 			///
				pow_medicare_dif_sd=pow_medicare_dif 						pow_mentallyill_dif_sd=pow_mentallyill_dif  ///
				pow_metoo_dif_sd=pow_metoo_dif 								pow_middleclass_dif_sd=pow_middleclass_dif 		///
				pow_migrantworker_dif_sd=pow_migrantworker_dif 				pow_military_dif_sd=pow_military_dif  ///
				pow_millennials_dif_sd=pow_millennials_dif 					pow_mothers_dif_sd=pow_mothers_dif 				///
				pow_muslims_dif_sd=pow_muslims_dif 							pow_nra_dif_sd=pow_nra_dif  ///
				pow_opioiduser_dif_sd=pow_opioiduser_dif 					pow_aids_dif_sd=pow_aids_dif 					///
				pow_police_dif_sd=pow_police_dif 							pow_polvictim_dif_sd=pow_polvictim_dif  ///
				pow_poorfamilies_dif_sd=pow_poorfamilies_dif 				pow_prisoners_dif_sd=pow_prisoners_dif 			///
				pow_refugees_dif_sd=pow_refugees_dif 						pow_retirees_dif_sd=pow_retirees_dif  ///
				pow_sexualharassvictim_dif_sd=pow_sexualharassvictim_dif	pow_richpeople_dif_sd=pow_richpeople_dif 		///
				pow_sexoffender_dif_sd=pow_sexoffender_dif  				pow_sexualharasser_dif_sd=pow_sexualharasser_dif /// 
				pow_singledad_dif_sd=pow_singledad_dif				 		pow_singlemom_dif_sd=pow_singlemom_dif 			///
				pow_smallbusiness_dif_sd=pow_smallbusiness_dif 				pow_smokers_dif_sd=pow_smokers_dif  ///
				pow_soldiers_dif_sd=pow_soldiers_dif		 				pow_taxpayers_dif_sd=pow_taxpayers_dif 			///
				pow_teachers_dif_sd=pow_teachers_dif 						pow_techworker_dif_sd=pow_techworker_dif  ///
				pow_transgender_dif_sd=pow_transgender_dif 					pow_unauthimm_dif_sd=pow_unauthimm_dif 			///
				pow_unemployed_dif_sd=pow_unemployed_dif 					pow_uninsured_dif_sd=pow_uninsured_dif  ///
				pow_veterans_dif_sd=pow_veterans_dif 						pow_voters_dif_sd=pow_voters_dif 				///
				pow_welfarecheats_dif_sd=pow_welfarecheats_dif 				pow_welfaremothers_dif_sd=pow_welfaremothers_dif  ///
				pow_whitecollar_dif_sd=pow_whitecollar_dif 					pow_whitemen_dif_sd=pow_whitemen_dif 			///
				pow_whitenat_dif_sd=pow_whitenat_dif 						pow_whitewomen_dif_sd=pow_whitewomen_dif  ///
				pow_workingclass_dif_sd=pow_workingclass_dif 				pow_youngblackmen_dif_sd=pow_youngblackmen_dif 	///
				pow_wrongfullyconvict_dif_sd=pow_wrongfullyconvict_dif ///
				des_africanamericans_dif_sd=des_africanamericans_dif		des_native_dif_sd=des_native_dif 				///
				des_asian_dif_sd=des_asian_dif								des_atheist_dif_sd=des_atheist_dif ///
				des_asylumseeker_dif_sd=des_asylumseeker_dif				des_attorneys_dif_sd=des_attorneys_dif 			///
				des_bigbanks_dif_sd=des_bigbanks_dif						des_bigcorps_dif_sd=des_bigcorps_dif ///
				des_blm_dif_sd=des_blm_dif									des_bluecollar_dif_sd=des_bluecollar_dif 		///
				des_tanf_dif_sd=des_tanf_dif								des_catholic_dif_sd=des_catholic_dif ///
				des_children_dif_sd=des_children_dif						des_collegeprof_dif_sd=des_collegeprof_dif 		///
				des_congress_dif_sd=des_congress_dif 						des_criminals_dif_sd=des_criminals_dif  ///
				des_entrepreneur_dif_sd=des_entrepreneur_dif				des_dreamers_dif_sd=des_dreamers_dif			///
				des_elderly_dif_sd=des_elderly_dif							des_environment_dif_sd=des_environment_dif  ///
				des_evangelical_dif_sd=des_evangelical_dif					des_exfelons_dif_sd=des_exfelons_dif			///
				des_farmers_dif_sd=des_farmers_dif							des_feminists_dif_sd=des_feminists_dif  ///
				des_gunmanuf_dif_sd=des_gunmanuf_dif 						des_gunowners_dif_sd=des_gunowners_dif 			///
				des_snap_dif_sd=des_snap_dif 								des_gaymen_dif_sd=des_gaymen_dif  ///
				des_gunvictims_dif_sd=des_gunvictims_dif 					des_homeless_dif_sd=des_homeless_dif 			///
				des_homeowners_dif_sd=des_homeowners_dif 					des_illegalaliens_dif_sd=des_illegalaliens_dif /// 
				des_insuranceco_dif_sd=des_insuranceco_dif 					des_ice_dif_sd=des_ice_dif 						///
				des_jews_dif_sd=des_jews_dif 								des_jobcreators_dif_sd=des_jobcreators_dif  ///
				des_laborunions_dif_sd=des_laborunions_dif 					des_latino_dif_sd=des_latino_dif 				///
				des_lesbians_dif_sd=des_lesbians_dif 						des_marijsmoker_dif_sd=des_marijsmoker_dif  ///
				des_media_dif_sd=des_media_dif 								des_medicaid_dif_sd=des_medicaid_dif 			///
				des_medicare_dif_sd=des_medicare_dif 						des_mentallyill_dif_sd=des_mentallyill_dif  ///
				des_metoo_dif_sd=des_metoo_dif 								des_middleclass_dif_sd=des_middleclass_dif 		///
				des_migrantworker_dif_sd=des_migrantworker_dif 				des_military_dif_sd=des_military_dif  ///
				des_millennials_dif_sd=des_millennials_dif 					des_mothers_dif_sd=des_mothers_dif 				///
				des_muslims_dif_sd=des_muslims_dif 							des_nra_dif_sd=des_nra_dif  ///
				des_opioiduser_dif_sd=des_opioiduser_dif 					des_aids_dif_sd=des_aids_dif 					///
				des_police_dif_sd=des_police_dif 							des_polvictim_dif_sd=des_polvictim_dif  ///
				des_poorfamilies_dif_sd=des_poorfamilies_dif 				des_prisoners_dif_sd=des_prisoners_dif 			///
				des_refugees_dif_sd=des_refugees_dif 						des_retirees_dif_sd=des_retirees_dif  ///
				des_sexualharassvictim_dif_sd=des_sexualharassvictim_dif	des_richpeople_dif_sd=des_richpeople_dif 		///
				des_sexoffender_dif_sd=des_sexoffender_dif  				des_sexualharasser_dif_sd=des_sexualharasser_dif /// 
				des_singledad_dif_sd=des_singledad_dif				 		des_singlemom_dif_sd=des_singlemom_dif 			///
				des_smallbusiness_dif_sd=des_smallbusiness_dif 				des_smokers_dif_sd=des_smokers_dif  ///
				des_soldiers_dif_sd=des_soldiers_dif		 				des_taxpayers_dif_sd=des_taxpayers_dif 			///
				des_teachers_dif_sd=des_teachers_dif 						des_techworker_dif_sd=des_techworker_dif  ///
				des_transgender_dif_sd=des_transgender_dif 					des_unauthimm_dif_sd=des_unauthimm_dif 			///
				des_unemployed_dif_sd=des_unemployed_dif 					des_uninsured_dif_sd=des_uninsured_dif  ///
				des_veterans_dif_sd=des_veterans_dif 						des_voters_dif_sd=des_voters_dif 				///
				des_welfarecheats_dif_sd=des_welfarecheats_dif 				des_welfaremothers_dif_sd=des_welfaremothers_dif  ///
				des_whitecollar_dif_sd=des_whitecollar_dif 					des_whitemen_dif_sd=des_whitemen_dif 			///
				des_whitenat_dif_sd=des_whitenat_dif 						des_whitewomen_dif_sd=des_whitewomen_dif  ///
				des_workingclass_dif_sd=des_workingclass_dif 				des_youngblackmen_dif_sd=des_youngblackmen_dif 	///
				des_wrongfullyconvict_dif_sd=des_wrongfullyconvict_dif ///
				, by(party_demindrep)
	
	drop if party_demindrep == .
	drop if party_demindrep == 1.5
	
  	rename *_dif_sd *

reshape long pow_ des_, i(party_demindrep) j(group) string
	rename *_ *
	
	gen pow_rep_gsd = pow if party_demindrep == 2
	gen des_rep_gsd = des if party_demindrep == 2
	gen pow_dem_gsd = pow if party_demindrep == 1
	gen des_dem_gsd = des if party_demindrep == 1
	
	drop pow des party_demindrep
	
	collapse pow_rep_gsd des_rep_gsd pow_dem_gsd des_dem_gsd, by(group)
	
	
	save "Exported Data Files/gsd_partyid.dta", replace
	
use PartisanWorldviews_Data_Final, clear

collapse (sd)	pow_africanamericans_dif_sd=pow_africanamericans_dif		pow_native_dif_sd=pow_native_dif 				///
				pow_asian_dif_sd=pow_asian_dif								pow_atheist_dif_sd=pow_atheist_dif ///
				pow_asylumseeker_dif_sd=pow_asylumseeker_dif				pow_attorneys_dif_sd=pow_attorneys_dif 			///
				pow_bigbanks_dif_sd=pow_bigbanks_dif						pow_bigcorps_dif_sd=pow_bigcorps_dif ///
				pow_blm_dif_sd=pow_blm_dif									pow_bluecollar_dif_sd=pow_bluecollar_dif 		///
				pow_tanf_dif_sd=pow_tanf_dif								pow_catholic_dif_sd=pow_catholic_dif ///
				pow_children_dif_sd=pow_children_dif						pow_collegeprof_dif_sd=pow_collegeprof_dif 		///
				pow_congress_dif_sd=pow_congress_dif 						pow_criminals_dif_sd=pow_criminals_dif  ///
				pow_entrepreneur_dif_sd=pow_entrepreneur_dif				pow_dreamers_dif_sd=pow_dreamers_dif			///
				pow_elderly_dif_sd=pow_elderly_dif							pow_environment_dif_sd=pow_environment_dif  ///
				pow_evangelical_dif_sd=pow_evangelical_dif					pow_exfelons_dif_sd=pow_exfelons_dif			///
				pow_farmers_dif_sd=pow_farmers_dif							pow_feminists_dif_sd=pow_feminists_dif  ///
				pow_gunmanuf_dif_sd=pow_gunmanuf_dif 						pow_gunowners_dif_sd=pow_gunowners_dif 			///
				pow_snap_dif_sd=pow_snap_dif 								pow_gaymen_dif_sd=pow_gaymen_dif  ///
				pow_gunvictims_dif_sd=pow_gunvictims_dif 					pow_homeless_dif_sd=pow_homeless_dif 			///
				pow_homeowners_dif_sd=pow_homeowners_dif 					pow_illegalaliens_dif_sd=pow_illegalaliens_dif /// 
				pow_insuranceco_dif_sd=pow_insuranceco_dif 					pow_ice_dif_sd=pow_ice_dif 						///
				pow_jews_dif_sd=pow_jews_dif 								pow_jobcreators_dif_sd=pow_jobcreators_dif  ///
				pow_laborunions_dif_sd=pow_laborunions_dif 					pow_latino_dif_sd=pow_latino_dif 				///
				pow_lesbians_dif_sd=pow_lesbians_dif 						pow_marijsmoker_dif_sd=pow_marijsmoker_dif  ///
				pow_media_dif_sd=pow_media_dif 								pow_medicaid_dif_sd=pow_medicaid_dif 			///
				pow_medicare_dif_sd=pow_medicare_dif 						pow_mentallyill_dif_sd=pow_mentallyill_dif  ///
				pow_metoo_dif_sd=pow_metoo_dif 								pow_middleclass_dif_sd=pow_middleclass_dif 		///
				pow_migrantworker_dif_sd=pow_migrantworker_dif 				pow_military_dif_sd=pow_military_dif  ///
				pow_millennials_dif_sd=pow_millennials_dif 					pow_mothers_dif_sd=pow_mothers_dif 				///
				pow_muslims_dif_sd=pow_muslims_dif 							pow_nra_dif_sd=pow_nra_dif  ///
				pow_opioiduser_dif_sd=pow_opioiduser_dif 					pow_aids_dif_sd=pow_aids_dif 					///
				pow_police_dif_sd=pow_police_dif 							pow_polvictim_dif_sd=pow_polvictim_dif  ///
				pow_poorfamilies_dif_sd=pow_poorfamilies_dif 				pow_prisoners_dif_sd=pow_prisoners_dif 			///
				pow_refugees_dif_sd=pow_refugees_dif 						pow_retirees_dif_sd=pow_retirees_dif  ///
				pow_sexualharassvictim_dif_sd=pow_sexualharassvictim_dif	pow_richpeople_dif_sd=pow_richpeople_dif 		///
				pow_sexoffender_dif_sd=pow_sexoffender_dif  				pow_sexualharasser_dif_sd=pow_sexualharasser_dif /// 
				pow_singledad_dif_sd=pow_singledad_dif				 		pow_singlemom_dif_sd=pow_singlemom_dif 			///
				pow_smallbusiness_dif_sd=pow_smallbusiness_dif 				pow_smokers_dif_sd=pow_smokers_dif  ///
				pow_soldiers_dif_sd=pow_soldiers_dif		 				pow_taxpayers_dif_sd=pow_taxpayers_dif 			///
				pow_teachers_dif_sd=pow_teachers_dif 						pow_techworker_dif_sd=pow_techworker_dif  ///
				pow_transgender_dif_sd=pow_transgender_dif 					pow_unauthimm_dif_sd=pow_unauthimm_dif 			///
				pow_unemployed_dif_sd=pow_unemployed_dif 					pow_uninsured_dif_sd=pow_uninsured_dif  ///
				pow_veterans_dif_sd=pow_veterans_dif 						pow_voters_dif_sd=pow_voters_dif 				///
				pow_welfarecheats_dif_sd=pow_welfarecheats_dif 				pow_welfaremothers_dif_sd=pow_welfaremothers_dif  ///
				pow_whitecollar_dif_sd=pow_whitecollar_dif 					pow_whitemen_dif_sd=pow_whitemen_dif 			///
				pow_whitenat_dif_sd=pow_whitenat_dif 						pow_whitewomen_dif_sd=pow_whitewomen_dif  ///
				pow_workingclass_dif_sd=pow_workingclass_dif 				pow_youngblackmen_dif_sd=pow_youngblackmen_dif 	///
				pow_wrongfullyconvict_dif_sd=pow_wrongfullyconvict_dif ///
				des_africanamericans_dif_sd=des_africanamericans_dif		des_native_dif_sd=des_native_dif 				///
				des_asian_dif_sd=des_asian_dif								des_atheist_dif_sd=des_atheist_dif ///
				des_asylumseeker_dif_sd=des_asylumseeker_dif				des_attorneys_dif_sd=des_attorneys_dif 			///
				des_bigbanks_dif_sd=des_bigbanks_dif						des_bigcorps_dif_sd=des_bigcorps_dif ///
				des_blm_dif_sd=des_blm_dif									des_bluecollar_dif_sd=des_bluecollar_dif 		///
				des_tanf_dif_sd=des_tanf_dif								des_catholic_dif_sd=des_catholic_dif ///
				des_children_dif_sd=des_children_dif						des_collegeprof_dif_sd=des_collegeprof_dif 		///
				des_congress_dif_sd=des_congress_dif 						des_criminals_dif_sd=des_criminals_dif  ///
				des_entrepreneur_dif_sd=des_entrepreneur_dif				des_dreamers_dif_sd=des_dreamers_dif			///
				des_elderly_dif_sd=des_elderly_dif							des_environment_dif_sd=des_environment_dif  ///
				des_evangelical_dif_sd=des_evangelical_dif					des_exfelons_dif_sd=des_exfelons_dif			///
				des_farmers_dif_sd=des_farmers_dif							des_feminists_dif_sd=des_feminists_dif  ///
				des_gunmanuf_dif_sd=des_gunmanuf_dif 						des_gunowners_dif_sd=des_gunowners_dif 			///
				des_snap_dif_sd=des_snap_dif 								des_gaymen_dif_sd=des_gaymen_dif  ///
				des_gunvictims_dif_sd=des_gunvictims_dif 					des_homeless_dif_sd=des_homeless_dif 			///
				des_homeowners_dif_sd=des_homeowners_dif 					des_illegalaliens_dif_sd=des_illegalaliens_dif /// 
				des_insuranceco_dif_sd=des_insuranceco_dif 					des_ice_dif_sd=des_ice_dif 						///
				des_jews_dif_sd=des_jews_dif 								des_jobcreators_dif_sd=des_jobcreators_dif  ///
				des_laborunions_dif_sd=des_laborunions_dif 					des_latino_dif_sd=des_latino_dif 				///
				des_lesbians_dif_sd=des_lesbians_dif 						des_marijsmoker_dif_sd=des_marijsmoker_dif  ///
				des_media_dif_sd=des_media_dif 								des_medicaid_dif_sd=des_medicaid_dif 			///
				des_medicare_dif_sd=des_medicare_dif 						des_mentallyill_dif_sd=des_mentallyill_dif  ///
				des_metoo_dif_sd=des_metoo_dif 								des_middleclass_dif_sd=des_middleclass_dif 		///
				des_migrantworker_dif_sd=des_migrantworker_dif 				des_military_dif_sd=des_military_dif  ///
				des_millennials_dif_sd=des_millennials_dif 					des_mothers_dif_sd=des_mothers_dif 				///
				des_muslims_dif_sd=des_muslims_dif 							des_nra_dif_sd=des_nra_dif  ///
				des_opioiduser_dif_sd=des_opioiduser_dif 					des_aids_dif_sd=des_aids_dif 					///
				des_police_dif_sd=des_police_dif 							des_polvictim_dif_sd=des_polvictim_dif  ///
				des_poorfamilies_dif_sd=des_poorfamilies_dif 				des_prisoners_dif_sd=des_prisoners_dif 			///
				des_refugees_dif_sd=des_refugees_dif 						des_retirees_dif_sd=des_retirees_dif  ///
				des_sexualharassvictim_dif_sd=des_sexualharassvictim_dif	des_richpeople_dif_sd=des_richpeople_dif 		///
				des_sexoffender_dif_sd=des_sexoffender_dif  				des_sexualharasser_dif_sd=des_sexualharasser_dif /// 
				des_singledad_dif_sd=des_singledad_dif				 		des_singlemom_dif_sd=des_singlemom_dif 			///
				des_smallbusiness_dif_sd=des_smallbusiness_dif 				des_smokers_dif_sd=des_smokers_dif  ///
				des_soldiers_dif_sd=des_soldiers_dif		 				des_taxpayers_dif_sd=des_taxpayers_dif 			///
				des_teachers_dif_sd=des_teachers_dif 						des_techworker_dif_sd=des_techworker_dif  ///
				des_transgender_dif_sd=des_transgender_dif 					des_unauthimm_dif_sd=des_unauthimm_dif 			///
				des_unemployed_dif_sd=des_unemployed_dif 					des_uninsured_dif_sd=des_uninsured_dif  ///
				des_veterans_dif_sd=des_veterans_dif 						des_voters_dif_sd=des_voters_dif 				///
				des_welfarecheats_dif_sd=des_welfarecheats_dif 				des_welfaremothers_dif_sd=des_welfaremothers_dif  ///
				des_whitecollar_dif_sd=des_whitecollar_dif 					des_whitemen_dif_sd=des_whitemen_dif 			///
				des_whitenat_dif_sd=des_whitenat_dif 						des_whitewomen_dif_sd=des_whitewomen_dif  ///
				des_workingclass_dif_sd=des_workingclass_dif 				des_youngblackmen_dif_sd=des_youngblackmen_dif 	///
				des_wrongfullyconvict_dif_sd=des_wrongfullyconvict_dif ///
				, by(party_demindrep)
	
	drop if party_demindrep == .
	drop if party_demindrep == 1.5
	
  	rename *_dif_sd *

reshape long pow_ des_, i(party_demindrep) j(group) string
	rename *_ *
	
	expand 2, gen(group_deserving)
	
	gen group2 = "pow_"+group if group_deserving == 0
	replace group2 = "des_"+group if group_deserving == 1
	
		
	order group group2 group_deserving
	
	gen all_dif_sd = pow if group_deserving == 0
	replace all_dif_sd = des if group_deserving == 1
	
	drop pow des 
	
reshape wide all_dif_sd, i(group2) j(party_demindrep)	
	sort group_deserving group
	
	rename all_dif_sd1 rep_dif_sd
	rename all_dif_sd2 dem_dif_sd	
		
gen pow_rep_dif_sd = rep_dif_sd if group_deserving == 0
gen des_rep_dif_sd = rep_dif_sd if group_deserving == 1

gen pow_dem_dif_sd = dem_dif_sd if group_deserving == 0
gen des_dem_dif_sd = dem_dif_sd if group_deserving == 1 



* 5e. To calculate the SD of the SDs (GSD) by Party ID

* Identify groups with high and low consensus for Republicans


sum des_rep_dif_sd
/* . sum des_rep_dif_sd

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
des_rep_di~d |         87    21.60868    3.891838   15.44411   29.67046

*/

 di  3.891838 /2
*1.945919


gen des_rep_sd_sdcat2 = 0 if group_deserving == 1
replace des_rep_sd_sdcat2 = .5 if des_rep_dif_sd > (21.60868 + 1.945919) & group_deserving==1
replace des_rep_sd_sdcat2 = -.5 if des_rep_dif_sd < (21.60868 - 1.945919) & group_deserving==1

replace des_rep_sd_sdcat2 = 1 if des_rep_dif_sd > (21.60868 + 3.891838) & group_deserving==1
replace des_rep_sd_sdcat2 = -1 if des_rep_dif_sd < (21.60868 - 3.891838) & group_deserving==1

replace des_rep_sd_sdcat2 = 1.5 if des_rep_dif_sd > (21.60868 + 3.891838 + 1.945919) & group_deserving==1
replace des_rep_sd_sdcat2 = -1.5 if des_rep_dif_sd < (21.60868 - 3.891838 - 1.945919) & group_deserving==1

replace des_rep_sd_sdcat2 = 2 if des_rep_dif_sd > (21.60868 + 3.891838 + 3.891838) & group_deserving==1
replace des_rep_sd_sdcat2 = -2 if des_rep_dif_sd < (21.60868 - 3.891838 - 3.891838) & group_deserving==1

gen consensus_rep_des_low = 0 if group_deserving == 1 
replace consensus_rep_des_low = 1 if des_rep_sd_sdcat > 1 & group_deserving == 1 


* 5f. Identify groups with high and low consensus for Democrats

sum des_dem_dif_sd
/* 

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
des_dem_di~d |         87    21.78208    2.231024   18.01428   28.45559
 */

 di 2.231024/2
*1.115512



gen des_dem_sd_sdcat2 = 0 if group_deserving == 1
replace des_dem_sd_sdcat2 = .5 if des_dem_dif_sd > (21.78208 + 1.115512) & group_deserving==1
replace des_dem_sd_sdcat2 = -.5 if des_dem_dif_sd < (21.78208 - 1.115512) & group_deserving==1

replace des_dem_sd_sdcat2 = 1 if des_dem_dif_sd > (21.78208 + 2.231024) & group_deserving==1
replace des_dem_sd_sdcat2 = -1 if des_dem_dif_sd < (21.78208 - 2.231024) & group_deserving==1

replace des_dem_sd_sdcat2 = 1.5 if des_dem_dif_sd > (21.78208 + 2.231024 + 1.115512) & group_deserving==1
replace des_dem_sd_sdcat2 = -1.5 if des_dem_dif_sd < (21.78208 - 2.231024 - 1.115512) & group_deserving==1

replace des_dem_sd_sdcat2 = 2 if des_dem_dif_sd > (21.78208 + 2.231024 + 2.231024) & group_deserving==1
replace des_dem_sd_sdcat2 = -2 if des_dem_dif_sd < (21.78208 - 2.231024 - 2.231024) & group_deserving==1


gen consensus_dem_des_low = 0 if group_deserving == 1
replace consensus_dem_des_low = 1 if des_dem_sd_sdcat > 1 & group_deserving==1




drop group2 rep_dif_sd dem_dif_sd group_deserving

collapse (mean) pow_rep_dif_sd des_rep_dif_sd pow_dem_dif_sd des_dem_dif_sd des_rep_sd_sdcat2 consensus_rep_des_low des_dem_sd_sdcat2 consensus_dem_des_low, by(group)

* save and export
save "Exported Data Files/sd_party_sdcat.dta", replace

/////////////////////////////
*6. Merge files
/////////////////////////////

use "Exported Data Files/sd_party_sdcat.dta", clear
	merge 1:1 group using "Exported Data Files/means_partyid.dta"
		drop _merge
	merge 1:1 group using "Exported Data Files/sd_allgroups_sdcat.dta"
		drop _merge

save "Exported Data Files/means_sdcats_consensus_merged.dta", replace
